cmake_minimum_required(VERSION 3.0.2)

set(swri_nodelet_SHARE ${swri_nodelet_PREFIX}/@CATKIN_PACKAGE_SHARE_DESTINATION@)

macro(swri_nodelet_add_node NODELET_NODENAME NODELET_NS NODELET_CLASS)
  find_package(roscpp REQUIRED)
  find_package(nodelet REQUIRED)
  find_package(Boost REQUIRED)
  # Workaround for header-only Boost issue in older versions of cmake:
  # https://gitlab.kitware.com/cmake/cmake/-/issues/18643
  add_library(${NODELET_NODENAME}_boost INTERFACE IMPORTED)
  set_property(TARGET ${NODELET_NODENAME}_boost PROPERTY
    INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR})
  set(NODELET_NODENAME ${NODELET_NODENAME})
  set(NODELET_NS ${NODELET_NS})
  set(NODELET_CLASS ${NODELET_CLASS})
  configure_file(${swri_nodelet_SHARE}/nodelet.cpp.in "${NODELET_NODENAME}.cpp")
  add_executable(${NODELET_NODENAME} "${NODELET_NODENAME}.cpp")
  target_include_directories(${NODELET_NODENAME} PRIVATE ${roscpp_INCLUDE} ${nodelet_INCLUDE})
  target_link_libraries(${NODELET_NODENAME} ${roscpp_LIBRARIES} ${nodelet_LIBRARIES} ${NODELET_NODENAME}_boost)
  unset(NODELET_NODENAME)
  unset(NODELET_NS)
  unset(NODELET_CLASS)
endmacro()
